home *** CD-ROM | disk | FTP | other *** search
/ Aminet 22 / Aminet 22 (1997)(GTI - Schatztruhe)[!][Dec 1997].iso / Aminet / dev / src / ConfigFileSrc.lha / ConfigFileSrc12 / RexxLibrary / Funcs / Get.c < prev    next >
Encoding:
Text File  |  1997-10-02  |  6.1 KB  |  257 lines

  1. /*
  2. **        $PROJECT: RexxConfigFile.library
  3. **        $FILE: Get.c
  4. **        $DESCRIPTION: rxcf_Get#?() functions
  5. **
  6. **        (C) Copyright 1997 Marcel Karas
  7. **             All Rights Reserved.
  8. */
  9.  
  10. IMPORT struct Library        *DOSBase;
  11. IMPORT struct Library        *RexxSysBase;
  12. IMPORT struct Library        *CFBase;
  13.  
  14. /****** rexxconfigfile.library/cf_GetItem ************************************
  15. *
  16. *   NAME
  17. *        cf_GetItem -- Get the contents of an item node or the default.
  18. *
  19. *   SYNOPSIS
  20. *        Contents = cf_GetItem(ItemNode,Type,Default)
  21. *
  22. *        CONTENTS cf_GetItem(ITEMNODE/N/A,TYPE/A,STYPE/A)
  23. *
  24. *   FUNCTION
  25. *        This function gets the contents of an item node. If Type not equal
  26. *        with the type of the item node the functions return the default.
  27. *
  28. *   INPUTS
  29. *        ItemNode - The item node.
  30. *        Type - Contents type (see cf_NewItem()).
  31. *        Default - Default contents.
  32. *
  33. *   RESULT
  34. *        Contents - The contents of the item node or the default.
  35. *
  36. *   SEE ALSO
  37. *        cf_GetItemNum()
  38. *
  39. ******************************************************************************
  40. *
  41. */
  42.  
  43. UWORD rxcf_GetItem ( RX_FUNC_ARGS, CFItem * ItemNode )
  44. {
  45.     RXCFItemConv ItemConv;
  46.     ULONG             Contents;
  47.  
  48.     if ( IsValidArg (RxMsg, 3) )
  49.     {
  50.         if ( ConvItemStrings (RxMsg, &ItemConv, 0, 2, 0) )
  51.         {
  52.             if ( Contents = cf_GetItem (ItemNode, ItemConv.Type, (LONG)RXARG3) )
  53.             {
  54.                 if ( ItemConv.Type == CF_ITYP_STRING )
  55.                     *ResStr = CreateArgstring ((STRPTR)Contents, *((STRPTR)Contents-1));
  56.                 else
  57.                     *ResStr = CreateNumArgStr (Contents);
  58.             }
  59.             return (RC_OK);
  60.         }
  61.     }
  62.  
  63.     return (RXERR_INVALID_ARG);
  64. }
  65.  
  66. /****** rexxconfigfile.library/cf_GetItemNum *********************************
  67. *
  68. *   NAME
  69. *        cf_GetItemNum -- Get the contents of an item node or the default.
  70. *
  71. *   SYNOPSIS
  72. *        Contents = cf_GetItemNum(ArgNode,Position,Type,Default)
  73. *
  74. *        CONTENTS cf_GetItemNum(ARGNODE/N/A,POSITION/A,TYPE/A,STYPE/A)
  75. *
  76. *   FUNCTION
  77. *        This function gets the contents of an item node from the specific
  78. *        position. If Type not equal with the type of the item node the
  79. *        function returns the default.
  80. *
  81. *   INPUTS
  82. *        ArgNode - The argument node.
  83. *        Position - Position of the item node (from 1 to X).
  84. *        Type - Contents type (see cf_NewItem()).
  85. *        Default - Default contents.
  86. *
  87. *   RESULT
  88. *        Contents - The contents of the item node or the default.
  89. *
  90. *   SEE ALSO
  91. *        cf_GetItem()
  92. *
  93. ******************************************************************************
  94. *
  95. */
  96.  
  97. UWORD rxcf_GetItemNum ( RX_FUNC_ARGS, CFArgument * ArgNode )
  98. {
  99.     RXCFItemConv ItemConv;
  100.     ULONG             Contents, Position;
  101.  
  102.     if ( IsValidArg (RxMsg, 4) )
  103.     {
  104.         if ( IsValidArg (RxMsg, 2) && ( StrToLong(RXARG2, (LONG *)&Position) != -1 ) )
  105.         {
  106.             if ( ConvItemStrings (RxMsg, &ItemConv, 0, 2, 0) )
  107.             {
  108.                 if ( Contents = cf_GetItemNum (ArgNode, Position, ItemConv.Type, (LONG)RXARG4) )
  109.                 {
  110.                     if ( ItemConv.Type == CF_ITYP_STRING )
  111.                         *ResStr = CreateArgstring ((STRPTR)Contents, *((STRPTR)Contents-1));
  112.                     else
  113.                         *ResStr = CreateNumArgStr (Contents);
  114.                 }
  115.                 return (RC_OK);
  116.             }
  117.         }
  118.     }
  119.  
  120.     return (RXERR_INVALID_ARG);
  121. }
  122.  
  123. /****** rexxconfigfile.library/cf_GetItemType ********************************
  124. *
  125. *   NAME
  126. *        cf_GetItemType -- Get the type of an item node.
  127. *
  128. *   SYNOPSIS
  129. *        Type = cf_GetItemType(ItemNode)
  130. *
  131. *        TYPE cf_GetItemType(ITEMNODE/N/A)
  132. *
  133. *   FUNCTION
  134. *        This function returns the contents type of an item node.
  135. *
  136. *   INPUTS
  137. *        ItemNode - The item node.
  138. *
  139. *   RESULT
  140. *        Type - Contents type (see cf_NewItem()) or ITYP_UNKOWN for
  141. *               an unkown specialtype.
  142. *
  143. *   SEE ALSO
  144. *        cf_GetItemSType(), cf_NewItem()
  145. *
  146. ******************************************************************************
  147. *
  148. */
  149.  
  150. UWORD rxcf_GetItemType ( RX_FUNC_ARGS, CFItem * ItemNode )
  151. {
  152.     RXCFStrConv    TypeConv;
  153.  
  154.     TypeToStr (&TypeConv, cf_GetItemType (ItemNode));
  155.  
  156.     *ResStr = CreateArgstring (TypeConv.Str, TypeConv.Len);
  157.     return (RC_OK);
  158. }
  159.  
  160. /****** rexxconfigfile.library/cf_GetItemSType *******************************
  161. *
  162. *   NAME
  163. *        cf_GetItemSType -- Get the special type of an item node.
  164. *
  165. *   SYNOPSIS
  166. *        SpecialType = cf_GetItemSType(ItemNode)
  167. *
  168. *        STYPE cf_GetItemSType(ITEMNODE/N/A)
  169. *
  170. *   FUNCTION
  171. *        This function returns the special type of an item node.
  172. *
  173. *   INPUTS
  174. *        ItemNode - The item node.
  175. *
  176. *   RESULT
  177. *        SpecialType - Special type (see cf_NewItem()) or STYP_UNKOWN for
  178. *                      an unkown specialtype.
  179. *
  180. *   SEE ALSO
  181. *        cf_GetItemType(), cf_NewItem()
  182. *
  183. ******************************************************************************
  184. *
  185. */
  186.  
  187. UWORD rxcf_GetItemSType ( RX_FUNC_ARGS, CFItem * ItemNode )
  188. {
  189.     RXCFStrConv    STypeConv;
  190.     UBYTE    Type  = cf_GetItemType  (ItemNode),
  191.             SType = cf_GetItemSType (ItemNode);
  192.  
  193.     if ( Type == CF_ITYP_NUMBER )
  194.         STypeNumToStr  (&STypeConv, SType);
  195.     else // if ( Type == CF_ITYP_BOOL )
  196.         STypeBoolToStr (&STypeConv, SType);
  197.  
  198.     *ResStr = CreateArgstring (STypeConv.Str, STypeConv.Len);
  199.     return (RC_OK);
  200. }
  201.  
  202. /****** rexxconfigfile.library/cf_GetItemOnly ********************************
  203. *
  204. *   NAME
  205. *        cf_GetItemOnly -- Get the contents of an item node.
  206. *
  207. *   SYNOPSIS
  208. *        Contents = cf_GetItemOnly(ItemNode)
  209. *
  210. *        CONTENTS cf_GetItemOnly(ITEMNODE/N/A)
  211. *
  212. *   FUNCTION
  213. *        This function gets the contents of an item node.
  214. *
  215. *   INPUTS
  216. *        ItemNode - The item node.
  217. *
  218. *   RESULT
  219. *        Contents - The Contents of the item node.
  220. *
  221. *   EXAMPLE
  222. *        ...
  223. *        Contents = cf_GetItemOnly(myItemNode)
  224. *        Type = cf_GetItemType(myItemNode)
  225. *
  226. *        SAY 'The contents of the item node is' Contents
  227. *        ...
  228. *
  229. *   SEE ALSO
  230. *        cf_GetItemNum(), cf_GetItem()
  231. *
  232. ******************************************************************************
  233. *
  234. */
  235.  
  236. UWORD rxcf_GetItemOnly ( RX_FUNC_ARGS, CFItem * ItemNode )
  237. {
  238.     ULONG Contents    = cf_GetItemOnly (ItemNode);
  239.     UBYTE    Type        = cf_GetItemType (ItemNode);
  240.  
  241.     if ( Type == CF_ITYP_STRING )
  242.         *ResStr = CreateArgstring ((STRPTR)Contents, StrLen ((STRPTR)Contents));
  243.  
  244.     else if ( Type == CF_ITYP_NUMBER )
  245.         *ResStr = CreateNumArgStr (Contents);
  246.  
  247.     else if ( Type == CF_ITYP_BOOL )
  248.     {
  249.         if ( Contents )
  250.             *ResStr = SetRC_TRUE  ();
  251.         else
  252.             *ResStr = SetRC_FALSE ();
  253.     }
  254.  
  255.     return (RC_OK);
  256. }
  257.